/**
 * 
 */
package fr.fermeManager.application.beans;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.util.List;

import org.jdesktop.observablecollections.ObservableCollections;

import fr.fermeManager.library.model.beans.Ferme;
import fr.fermeManager.library.model.beans.Transaction;
import fr.fermeManager.library.model.beans.TypeTransaction;

/**
 * @author Mo
 *
 */
public class BeanFerme{
	
	private Ferme ferme;
	
	private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
	
    /**
	 * @param ferme
	 */
	public BeanFerme(Ferme ferme) {
		super();
		this.ferme = ferme;
	}

	public void addPropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.removePropertyChangeListener(listener);
    }

	/**
	 * @param id
	 * @see fr.fermeManager.library.model.beans.Ferme#setId(int)
	 */
	public void setId(int id) {
		int oldVal = ferme.getId();
		changeSupport.firePropertyChange("id", oldVal, id);
		ferme.setId(id);
	}

	/**
	 * @param actif
	 * @see fr.fermeManager.library.model.beans.Ferme#setActif(boolean)
	 */
	public void setActif(boolean actif) {
		boolean oldVal = ferme.isActif();
		changeSupport.firePropertyChange("actif", oldVal, actif);
		ferme.setActif(actif);
	}

	/**
	 * @param libelle
	 * @see fr.fermeManager.library.model.beans.Ferme#setLibelle(java.lang.String)
	 */
	public void setLibelle(String libelle) {
		String oldVal = ferme.getLibelle();
		changeSupport.firePropertyChange("libelle", oldVal, libelle);
		ferme.setLibelle(libelle);
	}

	/**
	 * @param transactions
	 * @see fr.fermeManager.library.model.beans.Ferme#setTransactions(java.util.List)
	 */
	public void setTransactions(List<Transaction> transactions) {
		List<Transaction> oldVal = ferme.getTransactions();
		changeSupport.firePropertyChange("transactions", oldVal, transactions);
		ferme.setTransactions(ObservableCollections.observableList(transactions));
	}

	/**
	 * @param typesTransactions
	 * @see fr.fermeManager.library.model.beans.Ferme#setTypesTransactions(java.util.List)
	 */
	public void setTypesTransactions(List<TypeTransaction> typesTransactions) {
		List<TypeTransaction> oldVal = ferme.getTypesTransactions();
		changeSupport.firePropertyChange("typesTransactions", oldVal, typesTransactions);
		ferme.setTypesTransactions(ObservableCollections.observableList(typesTransactions));
	}

	/**
	 * @param description
	 * @see fr.fermeManager.library.model.beans.Ferme#setDescription(java.lang.String)
	 */
	public void setDescription(String description) {
		String oldVal = ferme.getDescription();
		changeSupport.firePropertyChange("description", oldVal, description);
		ferme.setDescription(description);
	}

	/**
	 * @return
	 * @see fr.fermeManager.library.model.beans.Ferme#getTransactions()
	 */
	public List<Transaction> getTransactions() {
		return ferme.getTransactions();
	}

	/**
	 * @return
	 * @see fr.fermeManager.library.model.beans.Ferme#getTypesTransactions()
	 */
	public List<TypeTransaction> getTypesTransactions() {
		return ferme.getTypesTransactions();
	}
}
